'use strict';
const Controller = require('egg').Controller;
const path = require("path");
const fs = require("fs");
class HxsController extends Controller {
    async zhonglei() {
        let class0 = this.ctx.request.query.classer;
        // console.log(class0,999);
        let res = await this.ctx.service.hxs.zhonglei(class0);
        // console.log(res);
        this.ctx.body = res;
    };
    async caidan() {
        // let class0 = this.ctx.request.query;
        let class1 = this.ctx.request.query.class1;
        let class2 = this.ctx.request.query.class2;
        // console.log(class0,999);
        let res = await this.ctx.service.hxs.caidan(class1, class2);
        // console.log(res);
        this.ctx.body = res;
    };
    async caidan2() {
        // let class0 = this.ctx.request.query;
        let class1 = this.ctx.request.query.class1;
        let class2 = this.ctx.request.query.class2;
        // console.log(class0,999);
        let res = await this.ctx.service.hxs.caidan2(class1, class2);
        // console.log(res.length);
        this.ctx.body = res;
    };
    async tuijianshangpin() {
        // let class0 = this.ctx.request.query;
        let class1 = this.ctx.request.query.classer1;
        let class2 = this.ctx.request.query.classer2;
        let class3 = this.ctx.request.query.classer3;
        console.log(class1, class2, class3, 999);
        let res = await this.ctx.service.hxs.tuijianshangpin(class1, class2, class3);
        // console.log(res);
        this.ctx.body = res;
    };
    async addshuju() {
        // let class0 = this.ctx.request.query;
        let title = this.ctx.request.body.title;
        let miaoshu = this.ctx.request.body.miaoshu;
        let tip = this.ctx.request.body.tip;
        let img = this.ctx.request.files[0];
        var oldpathimg = img.filepath;
        var basenameimg = path.basename(oldpathimg);
        var newpathimg = __dirname + "/../public/upload/" +basenameimg;
        fs.copyFile(oldpathimg, newpathimg, err => {
            fs.unlink(oldpathimg, (err) => { })
          })
          let newpath1img = "/public/upload/" +basenameimg;
        let img1 = this.ctx.request.files[1];
        let img2 = this.ctx.request.files[2];
        let img3 = this.ctx.request.files[3];
        let img4 = this.ctx.request.files[4];
        let img5 = this.ctx.request.files[5];
        var imgarr = [];
        imgarr.push(img1)
        imgarr.push(img2)
        imgarr.push(img3)
        imgarr.push(img4)
        imgarr.push(img5)
        console.log(img,imgarr);
        let classend = this.ctx.request.body.classend;
        let buzhou = this.ctx.request.body.strbuzou;
        let yongliao = this.ctx.request.body.stryongliao;
        let pushtime = this.ctx.request.body.pushtime;
        let newpath = []
            // console.log(this.ctx.request.files);
            imgarr.map(el => {
            var oldpath = el.filepath;
            var newpath1 = __dirname + "/../public/upload/" + path.basename(oldpath);
            fs.copyFile(oldpath, newpath1, err => {
                fs.unlink(oldpath, (err) => { })
            })
            newpath.push("/public/upload/" + path.basename(oldpath));
        })
        console.log(newpath,888);
        var strpastimg = newpath.toString();

        // console.log(title,miaoshu,tip,classend,img,buzhou,yongliao,buzouimg,pushtime,99999);
        let res = await this.ctx.service.hxs.addshuju(newpath1img,title,miaoshu,tip,yongliao,buzhou,pushtime,classend,strpastimg);
        console.log(res);
        this.ctx.body = res;
    };



}
module.exports = HxsController;